import Vue from 'vue'
import VueRouter from 'vue-router'

import HomeNav from "@/views/HomeNav.vue"
import HomeView from "@/views/HomeView.vue"
import ShopCart from "@/views/ShopCart.vue"
import OwnView from "@/views/OwnView.vue"
import CategoryView from "@/views/CategoryView.vue"
import GoosListDetail from "@/views/GoosListDetail.vue"
import StorePage from "@/views/StorePage.vue"
import StoreChat from "@/views/StoreChat.vue"
import StoreIntroduction from "@/views/StoreIntroduction.vue"
import GoodsProduct from "@/views/GoodsProduct.vue"
import GoodsComment from "@/views/GoodsComment.vue"
import LoginView from "@/views/LoginView.vue"
import SearchView from "@/views/SearchView.vue"
import VerificationCode from "@/views/VerificationCode.vue"
import PasswordLogin from "@/views/PasswordLogin.vue"
import RegisterCode from "@/views/RegisterCode.vue"
import PrivacyView from "@/views/PrivacyView.vue"
import MyselfView from "@/views/MyselfView.vue"
import MyFollow from "@/views/MyFollow.vue"
import MyCollection from "@/views/MyCollection.vue"
import MyFootprict from "@/views/MyFootprict.vue"
import MyOrder from "@/views/MyOrder.vue"
import PersonInfo from "@/views/PersonInfo.vue"
import ChangeNickname from "@/views/ChangeNickname.vue"
import LetterView from "@/views/LetterView.vue"
import ConfirmView from "@/views/ConfirmView.vue"
import AddAddress from "@/views/AddAddress.vue"
import MyAddress from "@/views/MyAddress.vue"
import PayView from "@/views/PayView.vue"
import SettingView from "@/views/SettingView.vue"



Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'nav',
    component: HomeNav,
    children: [
      {
        path: '',
        name: 'home',
        component: HomeView,
      },
      {
        path: '/cart',
        name: 'cart',
        component: ShopCart,
      },
      {
        path: '/own',
        name: 'own',
        component: OwnView,
      }
    ]
  },
  {
    path: '/category',
    name: 'category',
    component: CategoryView,
  },
  {
    path: '/goods',
    name: 'goods',
    component: GoosListDetail,
  },
  {
    path: '/store',
    name: 'store',
    component: StorePage,
  },
  {
    path: '/chat',
    name: 'chat',
    component: StoreChat,
  },
  {
    path: '/detail',
    name: 'detail',
    component: StoreIntroduction,
  },
  {
    path: '/product',
    name: 'product',
    component: GoodsProduct,
  },
  {
    path: '/comment',
    name: 'comment',
    component: GoodsComment,
  },
  {
    path: '/login',
    name: 'login',
    component: LoginView,
    redirect: '/login/password',
    children: [
      {
        path: '/login/password',
        name: 'password',
        component: PasswordLogin
      },
      {
        path: '/login/verification-code',
        name: 'verification-code',
        component: VerificationCode
      },
      {
        path: '/login/register',
        name: 'register',
        component: RegisterCode,

      }
    ]
  },
  {
    path: '/search',
    name: 'search',
    component: SearchView,
  },
  {
    path: '/privacy',
    name: 'privacy',
    component: PrivacyView
  },
  {
    path: '/myslef',
    name: 'me',
    component: MyselfView,
    children: [
      {
        path: '/myself/follow',
        name: 'follow',
        component: MyFollow
      },
      {
        path: '/myself/collection',
        name: 'collection',
        component: MyCollection
      },
      {
        path: '/myself/foot',
        name: 'foot',
        component: MyFootprict
      }
    ],
  },
  {
    path: '/order',
    name: 'order',
    component: MyOrder
  },
  {
    path: '/person',
    name: 'person',
    component: PersonInfo
  },
  {
    path: '/nickname',
    name: 'nick',
    component: ChangeNickname,
  },
  {
    path: '/letter',
    name: 'letter',
    component: LetterView,
  },
  {
    path: '/confirm',
    name: 'confirm',
    component: ConfirmView,
  },
  {
    path: '/address',
    name: 'address',
    component: AddAddress,
  },
  {
    path: '/address-list',
    name: 'list',
    component: MyAddress,
  },
  {
    path: '/pay',
    name: 'pay',
    component: PayView,
  },
  {
    path: '/set',
    name: 'set',
    component: SettingView,
  }

]

const router = new VueRouter({
  routes
})


router.afterEach(() => {
  window.scrollTo(0, 0);
  // chrome
  document.body.scrollTop = 0
  // firefox
  document.documentElement.scrollTop = 0
  // safari
  window.pageYOffset = 0
});
//或
router.beforeEach((to, from, next) => {
  to;
  from;
  // chrome
  document.body.scrollTop = 0
  // firefox
  document.documentElement.scrollTop = 0
  // safari
  window.pageYOffset = 0
  next()
})


export default router
